#include "TypeInfo.h"

namespace cppflib
{

namespace lang
{

/**
 *  Redefine assignment operator from BaseObject
 */
const TypeInfo& TypeInfo::operator=(const TypeInfo& t)
{
   this->name = t.name;
   return *this;
}

TypeInfo::TypeInfo(void)
{
}

TypeInfo::TypeInfo(const CFString & typeName)
{
   this->name = typeName;
}

#if defined(WIN32)
TypeInfo::TypeInfo(const type_info & typeInfo)
#elif defined(linux)
TypeInfo::TypeInfo(const std::type_info & typeInfo)
#endif
{
   this->name = typeInfo.name();
}

TypeInfo::~TypeInfo(void)
{
}

const CFString & TypeInfo::GetName() const
{
   return this->name;
}

bool TypeInfo::IsTypeOf(const TypeInfo & t) const
{
   return (this->name == t.GetName());
}

bool TypeInfo::IsTypeOf(const CFString & typeName) const
{
   return (this->name == typeName);
}

/**
 *  Use this method like this
 *
 *  TypeInfo::IsTypeOf(typeid(instance))
 */
#if defined(WIN32)
bool TypeInfo::IsTypeOf(const type_info & typeInfo) const
#elif defined(linux)
bool TypeInfo::IsTypeOf(const std::type_info & typeInfo) const
#endif
{
   CFString typeName(typeInfo.name());
   return (this->name == typeName);
}

/******************* global functions ********************/

bool operator==(const TypeInfo& t1, const TypeInfo& t2)
{
   return t1.IsTypeOf(t2);
}

bool operator!=(const TypeInfo& t1, const TypeInfo& t2)
{
   return !t1.IsTypeOf(t2);
}

}  // end of namespace lang

}  // end of namespace cppflib

